<?php
//初始数据
$app = 'christmas.php'; //程序
$account = 'admin'; //账号
$password = 'admin123'; //密码
session_start();
?>
<?php
//处理程序
$act = empty($_REQUEST['act'])? 'index':trim($_REQUEST['act']);
if($act == 'index'){ //首页
	
}elseif($act == 'admin'){
	if(empty($_SESSION['login_status'])){
		header('location:'.$app.'?act=login');
	}
	$logout_url = $app.'?act=logout';
}elseif($act == 'login'){ //登录

}elseif($act == 'check'){ //验证登录
	$post_account = empty($_REQUEST['account'])? '':trim($_REQUEST['account']);
	$post_password = empty($_REQUEST['password'])? '':trim($_REQUEST['password']);
	if($post_account == $account && $post_password == $password){
		$_SESSION['login_status'] = 1; //登录成功
		echo "登录成功";
		$url = $app.'?act=admin';
	}else{
		echo "登录失败";
		$url = $app.'?act=login';
	}	
}elseif($act == 'logout'){ //注销
	//unset($_SESSION['login_status']);
	session_destroy();
	header('location:'.$app.'?act=login');
}else{
	header('location:'.$app.'?act=login');
}

?>
<!--模板-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script src="http://www.ecmoban.com/content/themes/ecmoban2014/js/jquery.min.js"></script>
<title>Christmas</title>
<!--脚本-->
<script type="text/javascript">
//计时跳转
var time = 3;
function jump(obj, url){
	if(time >= 0){
		$(obj).html('页面将在'+time+'秒后跳转');
		time--;
		var t = setTimeout("jump('"+obj+"', '"+url+"')", 1000);
	}else{
		clearTimeout(t);
		location.href = url;
	}
}
//页面效果
var snow = new Object;
snow.src = 'images/snow_mid.png'; //素材
snow.snowSpeed = 1000; //生成时间（毫秒）
snow.downSpeed = 50; //下落时间（毫秒）
snow.quantity = 5; //同时生成数量
snow.create = function(){
	var w = window.innerWidth; //窗口宽度
	var h = window.innerHeight; //窗口高度
	qr = Math.ceil(Math.random()*this.quantity); //随机生成数量
	for(var i=0; i<qr; i++){
		var wr = Math.ceil(Math.random()*w); //随机宽度
		var style = 'left:'+wr+'px;';
		var x = '<img class="snow" style="'+style+'" src="'+this.src+'">';
		$("body").append(x);
	}
	var t = setTimeout('snow.create()', this.snowSpeed);
	if(false){
		clearTimeout(t);
	}
}
snow.down = function(){
	$("img.snow").each(function(){
		var t = $(this).css('top');
		var tv = parseInt(t.match(/\d+/g));
		tv += 1;
		if(tv < window.innerHeight){
			$(this).css({'top':tv+'px'}); //落下
		}else{
			$(this).remove(); //落地移除
		}
	})
	var t = setTimeout('snow.down()', this.downSpeed);
	if(false){
		clearTimeout(t);
	}	
}
</script>
<style>
body
{
	background-color:#000;
	background-image:url('images/background.jpg');
	background-repeat:no-repeat;
	background-attachment:fixed;
	background-position:center;
}
.snow{width:15px; height:15px; position:fixed;}
</style>
</head>
<body>
<?php if($act == 'index'){ ?>
<script>
snow.create();
snow.down();
</script>
<?php }elseif($act == 'admin'){ ?>
	<div>
		<p><a href="<?php echo $logout_url; ?>">退出</a></p>
	</div>
<?php }elseif($act == 'login'){ ?>
	<div>
		<form action="" method="POST">
			<h3>登录</h3>
			<p>账号：<input type="text" name="account"></p>
			<p>密码：<input type="password" name="password"></p>
			<p>
				<input type="hidden" name="act" value="check">
				<input type="submit" name="submit" value="登录">
			</p>
		</form>
	</div>	
<?php }elseif($act == 'check'){ ?>
	<p id="jump"></p>
	<script>
	$(function(){
		jump('#jump', '<?php echo $url; ?>');
	})
	</script>
<?php } ?>
<!--脚本-->
<script type="text/javascript">

</script>
</body>
</html>